<template>
  <div id="app">
    <!-- 如何让组件重载?  给他添加key属性 -->
    <Topbar :key="topBarKeyValue"></Topbar>
    <Header></Header>
    <router-view @fn="reloadTopbar"/>
    <Footer></Footer>

    <!-- 登录框组件 -->
    <Login v-show="isShowLoginModal"></Login>

    <!-- 提示框组件 -->
    <transition name="fade">
      <Toast v-show="isShowToast"></Toast>
    </transition>
    
  </div>
</template>

<script>
import Topbar from "@/components/Topbar.vue"
import Header from "@/components/Header.vue"
import Footer from "@/components/Footer.vue"
import Login from "@/components/Login.vue"
import Toast from "@/components/Toast.vue"
import { mapState } from "vuex"
export default {
    data () {
        return {
          topBarKeyValue: 1
        }
    },
    methods: { 
      // 重载方法(使页面重新刷新)
      reloadTopbar() {
        this.topBarKeyValue++; 
      }
      
    },
  /*   watch: {
    // 监听路由的变化
    "$route.path": {
      handler(newVal, oldVal){
        // console.log(newVal, oldVal)
        if(newVal !== oldVal){
          // key属性的值一变化，就会做组件重载，从而执行created函数
          console.log("组件重载！！！！");
          this.topBarKeyValue++;
        }
      }
    }, */
    computed: {
      ...mapState({
        isShowLoginModal: state => state.showLoginModal.isShowLoginModal,
        isShowToast: state => state.toastStatus.isShowToast
      })
    },
    components:{
      Topbar,Header,Footer,Login,Toast
    }
}
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}
// 定义进入过渡的开始状态  == 离开的结束状态
.fade-enter, .fade-leave-to {
  opacity: 0;
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .8s;
}
// 定义离开过渡的结束状态 == 离开的开始阶段
.fade-enter-to, .fade-leave {
  opacity: 1;
}
</style>
